A path (or filepath, file path, pathname, or similar) is a string that uniquely identifies an item in a hierarchical file system. Generally, a path is composed of directory names, special format specifiers, and optionally a filename, all separated by delimiters. This delimiter can vary by operating system, but popular, modern systems use the slash , backslash , or colon .
The case sensitivity of individual path components will vary based on operating system, or based on options specified at the time of a file system's mkfs or first use. In practice, this means that for a case-sensitive system, path components named and can coexist at the same level in the hierarchy, whereas for a case- insensitive file system, they cannot (an error will occur). macOS and Windows' native file systems are case-insensitive by default, whereas typical Linux file systems are case-sensitive. Includes a description of APFS, the default file system for macOS Windows file system treats file and directory names as case-insensitive. FOO.txt and foo.txt will be treated as equivalent files. Linux file system treats file and directory names as case-sensitive. FOO.txt and foo.txt will be treated as distinct files.
Case sensitivity in Linux refers to files and directories recognizing differences between lowercase and uppercase characters in filenames. For instance, "File.txt" and "file.txt" would both be treated as two distinct files. This concept is integral to Unix-like operating systems, including Linux.
A path can be either relative or absolute. A relative path is a path in relation to another, most often the working directory. An absolute path indicates a location regardless of the current directory; that is, it specifies all path components starting from the file system's Root directory, and does not depend on context like a relative path does.
Paths are also essential for locating hierarchically-organized network resources, as seen in URLs and UNC paths.
Around 1970, Unix introduced the slash as its directory separator.
Originally, MS-DOS did not support directories. When adding the feature, using the Unix standard of a slash was not a good option since many existing commands used a slash as the switch prefix (i.e., ). In contrast, Unix uses the dash as the switch prefix. The backslash was ultimately chosen instead for its similarity to the slash and not conflicting with existing commands. This convention continued into Windows. However, some areas of Windows do accept or understand Unix-style slashes also, such as PowerShell.
For instance, this C code is system- dependent and may fail on opposing systems:
with (Path("path") / "to" / "file.txt").open() as open_file:
...
Many applications on Unix-like systems (for example, secure copy, rcp, and rsync) use resource definitions such as , or URI schemes with the service name (here 'smb'), like .
Directory and file name comparisons are case-insensitive: "test.TXT" would match "Test.txt".
Windows understands the following kinds of paths:
In the Windows API, file I/O functions automatically convert into (except when using the prefix). Paths using standard Windows APIs (dating back to DOS and Win9x), were limited to 260 characters, or less, as defined by the environment variable . For backwards compatibility with legacy applications this limitation was not removed until Windows 10, build 1607, when it could be expanded to 32,767. Windows NT always supported the 32,767 path length internally but only if using Unicode APIs or forcing UNC paths by the prefix.
PowerShell allows slash-interoperability for backwards-compatibility:
Here is some text within a file
Some Windows interfaces allow or require UNC syntax for WebDAV share access, rather than a URL. The UNC syntax is extended with optional components to denote use of SSL and TCP/IP port number. Thus, the WebDAV URL of becomes .
When viewed remotely, the "SharedFolder" may have a name different from what a program on the server sees when opening "\SharedFolder". Instead, the SharedFolder name consists of an arbitrary name assigned during creation of the share.
Since UNCs start with two backslashes, and the backslash is also used for Escape sequence and in regular expressions, cases of leaning toothpick syndrome may arise. An escaped string for a regular expression matching a UNC begins with 8 backslashes because the string and regular expression both require escaping. This can be simplified by using , such as in C#, in Python, or in Perl.
|
|